<?php
class Admin_Model_Users extends Zend_Db_Table{
	protected $_name = 'users';
	protected $_primary = 'id';


	public function getWhere($u,$p){
	 		$se = $this->select();
	 		$se->where("username = ?", $u);
	 		$se->where("password = ?", $p);
	 		if($this->fetchRow($se)){
	 			$kq = $this->fetchRow($se)->toArray();
	 			return $kq;
	 		}else 
	 			return false;
	 	}
	 	public function changePass($arrParam){
	 		$data=array('password'=>$arrParam['passwordnew']);
	 		$where = array('username = ?'=>$arrParam['username'],'password = ?'=>$arrParam['password']);
	 		 return $this->update($data, $where);
	 	
	 	}
	 	public function  addUser($arrParam){
	 		$se = $this->select();
	 		$se->where("username = ?", $arrParam['username']);
	 		if($this->fetchRow($se)){
	 			return 0;
	 		}
	 		$row =  $this->fetchNew();
	 		$row->username   		= $arrParam['username'];
	 		$row->password			= $arrParam['password'];
	 		$row->role 		= $arrParam['role'];
	 		return $row->save();
	 	}
	 	public function getAll($order="desc"){
	 		$db = Zend_Registry::get('connectDb');
	 		$select = $db->select()
	 		->from("users");
	 		return $db->fetchAll($select);
	 	}
	 	public function editUser($arrParam) {
	 		$where = 'id = ' . $arrParam ['id'];
	 	
	 		$row = $this->fetchRow ( $where );
	 		$row->username   		= $arrParam['username'];
	 		$row->password			= $arrParam['password'];
	 		$row->role 		= $arrParam['role'];
	 		$row->save ();
	 	}
	 	public function getUser($arrParam){
	 		$se = $this->select ();
	 		$se->where ( "id= ?", $arrParam['id'] );
	 	
	 		return $this->fetchRow ( $se )->toArray ();
	 	}
	 	public function deleteUser($arrParam = null){
	 		$where = $this->getAdapter ()->quoteInto ( 'id = ?', $arrParam ["id"] );
	 		$this->delete ( $where );
	 	
	 	}

}